package miage.rest.resource.candidature;

import com.thoughtworks.xstream.XStream;
import java.util.List;
import miage.rest.db.Database;
import miage.rest.model.Nationalite;
import miage.rest.routing.UriTemplateFinder;
import miage.rest.xml.XstreamRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.Get;
import org.restlet.resource.ResourceException;
import org.restlet.resource.ServerResource;

/**
 *
 * @author marya
 */
public class NationalitesResource extends ServerResource{
    
    private final Database database;
    

    public NationalitesResource(Database database) {
        this.database = database;
    }

    @Override
    protected void doInit() throws ResourceException {
       
    }


    @Get
    public Representation doGet() throws Exception {
        Representation response = null;
        final String sqlNationalites = "SELECT id_nationalite , pays FROM nationalite ORDER BY id_nationalite ASC";
        List<Nationalite> nationalites = database.fetchAll(sqlNationalites, Nationalite.class);
        response = new XstreamRepresentation<List<Nationalite>>(nationalites);
        XStream xstream = ((XstreamRepresentation) response).getXstream();
        xstream = ((XstreamRepresentation) response).getXstream();
        xstream.alias("nationalites", List.class, nationalites.getClass());
                        xstream.processAnnotations(Nationalite.class);
        return response;
    }

}
